package use_case.processRental;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Hashtable;
import use_case.handlereturns.*;

public class RentalStatistics {
	private Hashtable<String, Integer> salesCountsByName;
	private Hashtable<String, Integer> salesCountsByGenre;

	public Hashtable<String, Integer> getSalesCountsByName() {
		return salesCountsByName;
	}

	public void setSalesCountsByName(Hashtable<String, Integer> salesCountsByName) {
		this.salesCountsByName = salesCountsByName;
	}
	
	public Hashtable<String, Integer> getSalesCountsByGenre() {
		return salesCountsByGenre;
	}

	public void setSalesCountsByGenre(Hashtable<String, Integer> salesCountsByGenre) {
		this.salesCountsByGenre = salesCountsByGenre;
	}
	
	RentalStatistics( )
	{
		salesCountsByName = new Hashtable<String, Integer>();
		salesCountsByGenre = new Hashtable<String, Integer>();
	}
	
	public void addSale( itemDescription itemDescription )
	{
		Integer currentCount = 1;
		if( salesCountsByName.containsKey(itemDescription.getName() ) )
			{
				currentCount = salesCountsByName.get(itemDescription.getName()) + 1;
			}

		salesCountsByName.put(itemDescription.getName(), currentCount);
		
		currentCount = 1;
		if( salesCountsByGenre.containsKey(itemDescription.getGenre()))
		{
			currentCount = salesCountsByGenre.get(itemDescription.getGenre()) + 1;
		}
		salesCountsByGenre.put( itemDescription.getGenre(), currentCount);
	}

	public void printStatsByName( BufferedWriter bufferedWriter ) throws IOException
	{
		for( String s : salesCountsByName.keySet())
		{
			bufferedWriter.write( String.format(s + "\t%d\n", salesCountsByName.get(s)));
		}
	}
	
	public void printStatsByGenre( BufferedWriter bufferedWriter ) throws IOException
	{
		for( String s : salesCountsByGenre.keySet() )
		{
			bufferedWriter.write( String.format( s + "\t%d\n", salesCountsByGenre.get(s)));
		}
	}
}
